define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/gold/index' + location.search,
                    add_url: 'goods/gold/add',
                    // edit_url: 'goods/gold/edit',
                    del_url: 'goods/gold/del',
                    multi_url: 'goods/gold/multi',
                    import_url: 'goods/gold/import',
                    table: 'goods_other',
                }
            });

            var table = $("#table");
            Fast.config.openArea = ['60%','70%'];
            // //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='invite']", form).addClass("selectpage").data("source", "general/staff/index").data("primaryKey", "invite").data("field", "invite").data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goods_sn', title: __('Goods_sn'), operate: 'LIKE'},
                        {field: 'personal.account', title: __('Personal.account'), operate: 'LIKE'},
                        {field: 'gamename', title: __('Gamename'), operate: 'LIKE'},
                        {field: 'type_name', title: __('Type_name'), operate: 'LIKE'},
                        {field: 'title', title: __('Title'), operate: 'LIKE',
                            cellStyle:function (value, row, index) {
                                return {
                                    css: {
                                        "min-width": "100px",
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width": "400px",
                                        "cursor": "pointer"
                                    }
                                }
                            },
                            formatter:function(value,row,index){
                                value = value?value:'';
                                var length = value.length;
                                if(length&&length>35){length = 35;}
                                return"<span title ='"+value+"'>"+value.substring(0,length)+"</span>"
                            }


                        },
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'plat', title: __('Plat'), operate: 'LIKE'},
                        {field: 'cross', title: __('跨区'), searchList: $.getJSON("games/cross/crossList")},
                        {field: 'area', title: __('Area'), operate: 'LIKE'},
                        {field: 'server', title: __('Server'), operate: 'LIKE'},
                        {field: 'havetime', title: __('Havetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Type'),searchList: {"1":"上架","2":"下架","5":"平台下架"}, formatter: Table.api.formatter.flag},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'invite', title: __('Invite'), operate: 'LIKE'},
                        {field: 'method', title: __('Method'),searchList: {"1":__('平台代发'),"2":__('卖家发货')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'coin_type', title: __('Coin_type'),searchList: {"1":__('邮寄交易'),"2":__('拍卖交易'),"3":__('面对面交易')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'goods/gold/info',

                                },
                                {
                                        name: 'down',
                                        text: __(''),
                                        title: __('下架'),
                                        classname: 'btn btn-xs btn-info btn-dialog',
                                        icon: 'fa fa-pencil',
                                        url: 'goods/gold/edit',
    
                                    },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        info: function () {
            Controller.api.bindevent();
        },
        down: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
